/*
 * @lc app=leetcode.cn id=495 lang=javascript
 *
 * [495] 提莫攻击
 */

// @lc code=start
/**
 * @param {number[]} timeSeries
 * @param {number} duration
 * @return {number}
 */
var findPoisonedDuration = function(timeSeries, duration) {
    let sum = 0;
    for (let i = 0; i < timeSeries.length - 1; i++) {
        const time = timeSeries[i];
        const next = timeSeries[i + 1];
        if (time + duration > next) {
            sum += next - time;
        } else {
            sum += duration;
        }
    }
    return sum + duration;
};
// @lc code=end

